package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemProjectInfoBo;
import com.cw.jeeyt.dao.model.system.SystemProjectInfoDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 项目信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemProjectInfoConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemProjectInfoBo do2Bo(SystemProjectInfoDo model) {
        if (model == null) {
            return null;
        }
        SystemProjectInfoBo bo = new SystemProjectInfoBo();
        bo.setId(model.getId());
        bo.setProjectCode(model.getProjectCode());
        bo.setProjectName(model.getProjectName());
        bo.setProjectType(model.getProjectType());
        bo.setProjectSvnUrl(model.getProjectSvnUrl());
        bo.setProjectWebserviceUrl(model.getProjectWebserviceUrl());
        bo.setProjectAbsolutePath(model.getProjectAbsolutePath());
        bo.setTemplateId(model.getTemplateId());
        bo.setProjectComment(model.getProjectComment());
        bo.setDatabaseType(model.getDatabaseType());
        bo.setJdbcDriverClass(model.getJdbcDriverClass());
        bo.setJdbcUserName(model.getJdbcUserName());
        bo.setJdbcUserPassword(model.getJdbcUserPassword());
        bo.setJdbcUrl(model.getJdbcUrl());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemProjectInfoDo bo2Do(SystemProjectInfoBo bo) {
        if (bo == null) {
            return null;
        }
        SystemProjectInfoDo model = new SystemProjectInfoDo();
        model.setId(bo.getId());
        model.setProjectCode(bo.getProjectCode());
        model.setProjectName(bo.getProjectName());
        model.setProjectType(bo.getProjectType());
        model.setProjectSvnUrl(bo.getProjectSvnUrl());
        model.setProjectWebserviceUrl(bo.getProjectWebserviceUrl());
        model.setProjectAbsolutePath(bo.getProjectAbsolutePath());
        model.setTemplateId(bo.getTemplateId());
        model.setProjectComment(bo.getProjectComment());
        model.setDatabaseType(bo.getDatabaseType());
        model.setJdbcDriverClass(bo.getJdbcDriverClass());
        model.setJdbcUserName(bo.getJdbcUserName());
        model.setJdbcUserPassword(bo.getJdbcUserPassword());
        model.setJdbcUrl(bo.getJdbcUrl());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemProjectInfoBo> doList2BoList(List<SystemProjectInfoDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemProjectInfoConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemProjectInfoDo> boList2DoList(List<SystemProjectInfoBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemProjectInfoConverter::bo2Do));
    }
}